const { readdirSync } = require("fs");

const getDirectories = (source) =>
  readdirSync(source, { withFileTypes: true })
    .filter((dirent) => dirent.isDirectory())
    .map((dirent) => {
      return { name: dirent.name, value: dirent.name };
    });

module.exports = (plop) => {
  let directories = getDirectories("src/pages");
  plop.setGenerator("FormModal", {
    description: "Create a Modal",
    // User input prompts provided as arguments to the template
    prompts: [
      {
        // Raw text input
        type: "input",
        // Variable name for this input
        name: "name",
        // Prompt to display on command line
        message: "What is your BasicDialog name?",
      },
    ],
    actions: (data) => {
      const path = "src/BasicDialog/";

      let actions = [
        {
          // Add a new file
          type: "add",
          // Path for the new file
          path: path + "{{pascalCase name}}/{{pascalCase name}}ModalOut.vue",
          // Handlebars template used to generate content of new file
          templateFile: "plop-templates/FormModal/ModalOut.vue.hbs",
        },
        {
          type: "add",
          path: path + "{{pascalCase name}}/{{pascalCase name}}Modal.vue",
          templateFile: "plop-templates/FormModal/ModalIn.vue.hbs",
        },
      ];

      return actions;
    },
  });

  plop.setGenerator("Modal", {
    description: "Create a Modal",
    // User input prompts provided as arguments to the template
    prompts: [
      {
        // Raw text input
        type: "input",
        // Variable name for this input
        name: "name",
        // Prompt to display on command line
        message: "What is your BasicDialog name?",
      },
    ],
    actions: (data) => {
      const path = "src/BasicDialog/";

      let actions = [
        {
          // Add a new file
          type: "add",
          // Path for the new file
          path: path + "{{pascalCase name}}/{{pascalCase name}}ModalOut.vue",
          // Handlebars template used to generate content of new file
          templateFile: "plop-templates/Modal/ModalOut.vue.hbs",
        },
        {
          type: "add",
          path: path + "{{pascalCase name}}/{{pascalCase name}}Modal.vue",
          templateFile: "plop-templates/Modal/ModalIn.vue.hbs",
        },
      ];

      return actions;
    },
  });
};
